package main

/**
 * Forward declaration of guess API.
 * @param  num   your guess
 * @return 	     -1 if num is lower than the guess number
 *			      1 if num is higher than the guess number
 *               otherwise return 0
 * func guess(num int) int;
 */

var pick int

func guess(num int) int {
	if num < pick {
		return 1
	} else if num > pick {
		return -1
	}
	return 0
}

func guessNumber(n int) int {
	left := 1
	right := n
	for left <= right {
		mid := left + (right-left)/2
		diff := guess(mid)
		if diff > 0 {
			left = mid + 1
		} else if diff < 0 {
			right = mid - 1
		} else {
			return mid
		}
	}
	return 0
}

func main() {
	pick = 6
	println(guessNumber(10))
	pick = 1
	println(guessNumber(1))
	pick = 1
	println(guessNumber(2))
	pick = 2
	println(guessNumber(2))
}
